# 此程序用于生成仿真所需速度分段函数

import numpy as np
import matplotlib.pyplot as plt
from math import *
import pandas as pd

n = 200
para = np.linspace(1.08, 0, n)
print(para)
r = 50
# 渐开线参数方程:
x = r * (np.cos(para + 1.082) + para * np.sin(para + 1.082))
y = r * (np.sin(para + 1.082) - para * np.cos(para + 1.082))
plt.plot(x - x[-1], y - y[-1])
print(x[0] - x[-1], y[0] - y[-1])
plt.show()

# print("x: \n")
# print(x)
# print("y: \n{}".format(y))
# 定义线速度
v = 0.008
# 离散化:
k = 0
vx = np.zeros(n - 1)
vy = np.zeros(n - 1)
time = np.zeros(n)
# 输出矩阵 fvx和fvy是水平和竖直方向速度的分段函数
fvx = np.zeros((n - 1, 3))
fvy = np.zeros((n - 1, 3))
while k <= n - 2:
    s = sqrt((x[k] - x[k + 1]) ** 2 + (y[k] - y[k + 1]) ** 2)
    dt = s / v
    time[k + 1] = time[k] + dt
    dx = x[k + 1] - x[k]
    dy = y[k + 1] - y[k]
    vx[k] = dx / dt
    vy[k] = dy / dt
    fvx[k, 0] = time[k]
    fvx[k, 1] = time[k + 1]
    fvx[k, 2] = vx[k]
    fvy[k, 0] = time[k]
    fvy[k, 1] = time[k + 1]
    fvy[k, 2] = vy[k]
    k += 1
    pass
print(fvx)

fvx = pd.DataFrame(fvx)
fvy = pd.DataFrame(fvy)
fvx.to_excel('fvx.xlsx', index=False, header=None)
fvy.to_excel('fvy.xlsx', index=False, header=None)
